<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of addressbooks_model
 *
 * @author win7
 */
class addressbooks_model extends admin_model {

    public function __construct() {
        parent::__construct();
        $this->table = 'addressbook';
        $this->select = array('user.username ', 'addressbook.* ', 'cities_language.title', 'cities_language.lang');
        $this->order = array('addressbook.id' => metohd_get_uri('sort', 'desc'));
        $this->where = array('cities_language.lang' => 'ar');
        $this->join = array(
            'user' => 'user.id = addressbook.user_id',
            'cities' => 'cities.id = addressbook.cities_id',
            'cities_language' => 'cities.id = cities_language.city_id'
        );
        $this->columns_op = array(
            'user_id' => 'Callback_get_userid_with_username',
            'create_date >=' => 'Callback_get_date'
        );
    }

    public function is_used_in_invoices($id) {
        if (count($id) > 0) {
            $this->db->where_in('addressbook_id', $id);
        } else {
            $this->db->where('addressbook_id', $id);
        }
        $sql = $this->db->get_where('order_invoices');
        if ($sql->num_rows()) {
            $this->themes->set_message(array('url' => 'addressbooks/', 'type' => 'error', 'message' => "message_cannott_delete_it_is_used_in_some_invoices"));
        }
    }

}

?>
